#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

static vector<vector<uint64_t>> read_data(const string& filename) {
    ifstream file {filename};
    if (!file.is_open()) {
        cerr << "Error: cannot open file " << filename << endl;
    }

    vector<vector<uint64_t>> data;
    for (int i = 0; ; ++i) {
        vector<uint64_t> row;
        for (int j = 0; ; ++j) {
            unsigned value;
            file >> value;
            row.push_back(value);
            if (i == j)
                break;
        }
        data.push_back(row);
        if (file.eof())
            break;
    }

    file.close();

    return data;
}

static void show_data(const vector<vector<uint64_t>>& data) {
    for (const auto& row : data) {
        for (auto value : row) {
            cout << value << " ";
        }
        cout << endl;
    }
}

int main() {
    vector<vector<uint64_t>> data = read_data("pe67.txt");
    // show_data(data);

    for (int i = data.size() - 2; i >= 0; --i) {
        for (int j = 0; j < data[i].size(); ++j) {
            data[i][j] += max(data[i + 1][j], data[i + 1][j + 1]);
        }
    }

    cout << data[0][0] << endl;

    return 0; // 7273
}